home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
A.C.E. 2
/
ACE CD 2.iso
/
FILES
/
UTILS
/
PROCAL13.DMS
/
PROCAL13.adf
/
Rexx
/
table.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1991-12-11
|
6KB
|
160 lines
/* Table S. Dicker 6-Aug-89 */
/* */
/* ARexx program used to construct a table of equally spaced */
/* values. Select a range of cells to contain the table and then */
/* execute this program. You must supply a starting value for the */
/* table. You may also supply the increment between table entries */
/* (defaults to 1). Cells in the selected range are filled row by */
/* row. */
/* */
/* Example: Table 50 5 */
/* Fills the selected range with 50, 55, 60, etc. */
signal on error /* Trap host command errors. */
arg start_value increment /* Retrieve command line arguments. */
address 'Advantage' /* Send commands to Advantage. */
options results /* Enable return of string results. */
if start_value = 0 then /* If no starting value was supplied, */
do /* display an error message and quit. */
'DrawMessage'
"You must supply a starting value for the table"
exit 10
end
if increment = "" then /* If no increment was supplied, */
increment = 1 /* default to 1. */
'Current' /* Determine current selected range. */
range = result
colon_posn = pos(":",range) /* Look for colon delimiter in range. */
if colon_posn = 0 then /* If no colon, this is not a range. */
do /* Set the start and end cells to */
start_cell = range /* the selected cell. */
end_cell = range
end
else /* Otherwise, it is a range. */
/* Extract the start/end cells from the specified range. */
do
start_cell = left(range,colon_posn - 1)
end_cell = substr(range,colon_posn + 1)
end
start_column = GetColumn(start_cell) /* Determine range of columns */
end_column = GetColumn(end_cell) /* to be filled. */
start_row = GetRow(start_cell) /* Determine range of rows */
end_row = GetRow(end_cell) /* to be filled. */
next_entry = start_value /* Initialize table entry value. */
/* Fill cells with table of values, row by row. */
do rownum = start_row to end_row
column = start_column /* Reset column pointer. */
/* Fill all columns in the current row. */
do until c2d(column) > c2d(end_column)
/* Build complete cell name from row and column. */
next_cell = column || rownum
/* Select the cell to be modified. */
'SelectCell'
value(next_cell)
/* Load the value into the cell. */
'PutCell'
next_entry
/* Advance to the next column and table entry. */
column = NextColumn(column)
next_entry = next_entry + increment
end
end rownum
/* Reselect the original range of cells. */
'SelectRange'
value(start_cell)
value(end_cell)
exit /* That's all folks! */
/* >>> Host command error handler <<< */
Error:
exit rc /* Just bail out and return error code. */
/* ----------------------------------------------------------------- */
/* Internal Functions (subroutines) */
/* ----------------------------------------------------------------- */
/* == GetRow: Extract the row number from a cell name. == */
GetRow: procedure
arg CellName /* Function expects to be passed a cell name. */
/* Find the first numeric digit in the cell name. */
start_number = verify(CellName,"0123456789","Match")
/* Extract all characters starting at the first digit and continuing */
/* to the end of the cell name. */
rownum = substr(CellName,start_number)
return rownum
/* == GetColumn: Extract the column label from a cell name. == */
GetColumn: procedure
arg CellName /* Function expects to be passed a cell name. */
/* Find the first numeric digit in the cell name. */
start_number = verify(CellName,"0123456789","Match")
/* Extract all characters in the cell name up to the first numeric */
/* character (start of row number). */
column = left(CellName,start_number-1)
return column
/* == NextColumn: Given the current column label, determine the label == */
/* == for the next sequential column. NOTE: This is a == */
/* == recursive function. == */
NextColumn: procedure
arg ThisColumn /* Function expects to be passed a column label. */
/* If the column label is empty (null string), then we must be */
/* starting a new group of column labels (for example, going */
/* from column ZZ to column AAA. Return an "A". */
if length(ThisColumn) = 0 then
new_column = "A"
/* Otherwise, we must advance the last character in the column */
/* name to the next sequential alphabetic character. */
else
do
col_number = , /* Convert last character */
c2d( right(ThisColumn,1) ) /* to decimal value. */
col_number = col_number + 1 /* Increment to next character. */
new_char = d2c(col_number) /* Convert back to a character. */
/* If we've gone past 'Z', find the next column for the column */
/* label minus the last character and then append an "A" to */
/* this label (start of a new label set). */
if new_char > "Z" then
do
temp_column = left( ThisColumn, length(ThisColumn)-1 )
new_column = NextColumn(temp_column) || "A"
end
/* Otherwise, replace the last character of the column label */
/* with the next sequential character. */
else
new_column = overlay(new_char,ThisColumn,length(ThisColumn))
end
return new_column